import React, { useState, useEffect } from 'react'
import { View, Text } from '@tarojs/components'
import { AtSearchBar } from 'taro-ui'
// import taro from '@tarojs/taro'
import NewsContent from '../../compontents/newsContent'
import ToLogin from '../../compontents/toLogin'
import Taro, { useShareAppMessage, useShareTimeline } from '@tarojs/taro'

import "taro-ui/dist/style/components/search-bar.scss";
import "taro-ui/dist/style/components/button.scss";
import "taro-ui/dist/style/components/icon.scss";
import Navbar from '../../compontents/navbar/index'

import './index.less'

export default (props: any) => {
  const [title, setTitle] = useState('')
  let t1 = ''
  const onChange = (e) => {
    t1 = e
  }
  const onActionClick = () => {
    setTitle(t1)
  }
  useShareAppMessage(res => {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: 'U你校园广场',
      path: '/pages/news/index'
    }
  })

  useShareTimeline(() => {
    return {
      title: 'U你校园广场',
      path: '/pages/news/index'
    }
  })
  return (
    <View className='active flex flex-direction '>
      <ToLogin url='/pages/news/index'></ToLogin>
      <View className='flex1 contentBox'>
        <AtSearchBar
          className='search'
          value={''}
          onChange={onChange}
          onActionClick={onActionClick}
        />
        <NewsContent title={title} />
      </View>
      <Navbar></Navbar>
    </View>
  );
};
